#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
Simplified BSD License (BSD)
Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this 
      list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice, 
      this list of conditions and the following disclaimer in the documentation 
      and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

#region Record of Change
//             							CHANGE HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | DEVELOPER  | DESCRIPTION                                              |
// -------------------------------------------------------------------------------------
// | 12-Nov-09 | HaiNM      | First creation.                                          |
// -------------------------------------------------------------------------------------
//
#endregion

#region Record of Audit
//             							REVIEW HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | REVIEWER   | NOTES                                                    |
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
//
#endregion

#region Using directives
using System;
using System.Drawing;
using System.Windows.Forms;

using Thn;
#endregion

namespace Thn.Interface.Vcl
{
    /// <summary>
    /// Abstract base class for all virtual controls. This class implements interface <see cref="IVirtualControl"/>
    /// to make it easier for children descendant without offering any functionalities.
    /// </summary>
#if DEBUG
    public
#else
    public
#endif
 abstract class VirtualControlBase : IVirtualControl
    {
        #region Render
        /// <summary>
        /// Paint this control.
        /// </summary>
        /// <param name="canvas">The graphics canvas to paint on.</param>
        /// <param name="context">The current renderation context.</param>
        protected virtual void OnRender(Graphics canvas, RenderContext context) { }
        #endregion

        #region Boundary

        #region On Moved
        /// <summary>
        /// This method is raised when the location of this control is modified.
        /// </summary>
        protected virtual void OnMoved() { }
        #endregion

        #region On Resized
        /// <summary>
        /// This method is raised when the size of this control is modified.
        /// </summary>
        protected virtual void OnResized() { }
        #endregion

        #endregion

        #region Focus

        #region On Got Focus
        /// <summary>
        /// This method is invoked to inform this control that it has received focus.
        /// </summary>
        protected virtual void OnGotFocus() { }
        #endregion

        #region On Lost Focus
        /// <summary>
        /// This method is invoked to inform this control that it has lost focus.
        /// </summary>
        protected virtual void OnLostFocus() { }
        #endregion

        #endregion

        #region Mouse Events

        #region On Mouse Enter
        /// <summary>
        /// This method is invoked to inform this control that it has received Mouse Enter event.
        /// </summary>
        protected virtual void OnMouseEnter() { }
        #endregion

        #region On Mouse Leave
        /// <summary>
        /// This method is invoked to inform this control that it has received Mouse Leave event.
        /// </summary>
        protected virtual void OnMouseLeave() { }
        #endregion

        #region On Mouse Move
        /// <summary>
        /// This method is invoked to inform this control that it has received Mouse Move event.
        /// </summary>
        protected virtual void OnMouseMove(MouseEventArgs e) { }
        #endregion

        #region On Mouse Up
        /// <summary>
        /// This method is invoked to inform this control that it has received Mouse Up event.
        /// </summary>
        protected virtual void OnMouseUp(MouseEventArgs e) { }
        #endregion

        #region On Mouse Down
        /// <summary>
        /// This method is invoked to inform this control that it has received Mouse Down event.
        /// </summary>
        protected virtual void OnMouseDown(MouseEventArgs e) { }
        #endregion

        #region On Mouse Click
        /// <summary>
        /// This method is invoked to inform this control that it has received Mouse Click event.
        /// </summary>
        protected virtual void OnMouseClick(MouseEventArgs e) { }
        #endregion

        #region On Mouse Double Click
        /// <summary>
        /// This method is invoked to inform this control that it has received Mouse Double Click event.
        /// </summary>
        protected virtual void OnMouseDoubleClick(MouseEventArgs e) { }
        #endregion

        #endregion

        #region Keyboard Events

        #region On Key Up
        /// <summary>
        /// This method is invoked to inform this control that it has received Key Up event.
        /// </summary>
        protected virtual void OnKeyUp(KeyEventArgs e) { }
        #endregion

        #region On Key Down
        /// <summary>
        /// This method is invoked to inform this control that it has received Key Down event.
        /// </summary>
        protected virtual void OnKeyDown(KeyPressEventArgs e) { }
        #endregion

        #region On Key Press
        /// <summary>
        /// This method is invoked to inform this control that it has received Key Press event.
        /// </summary>
        protected virtual void OnKeyPress(KeyEventArgs e) { }
        #endregion

        #endregion

        #region IVirtualControl Members

        #region Boundary

        #region Location
        private Point mLocation = Point.Empty;
        /// <summary>
        /// Gets/Sets top-left coordinate.
        /// </summary>
        public Point Location
        {
            get { return mLocation; }
            set
            {
                mLocation = value;
                OnMoved();
            }
        }
        #endregion

        #region Size
        private Size mSize = Size.Empty;
        /// <summary>
        /// Gets/Sets dimensions.
        /// </summary>
        public Size Size
        {
            get { return mSize; }
            set
            {
                mSize = value;
                OnResized();
            }
        }
        #endregion

        #region Set Bounds
        /// <summary>
        /// Set the boundary of this control.
        /// </summary>
        /// <param name="left">x-axis coordinate.</param>
        /// <param name="top">y-axis coordinate.</param>
        /// <param name="width">horizontal size.</param>
        /// <param name="height">vertical size.</param>
        public void SetBounds(int left, int top, int width, int height)
        {
            if ((mLocation.X != left) || (mLocation.Y != top))
            {
                mLocation = new Point(left, top);
                OnMoved();
            }
            #region Defensive tracing
            else
            {
                //not different from current values.
            }
            #endregion

            if ((mSize.Width != width) || (mSize.Height != height))
            {
                mSize = new Size(width, height);
                OnResized();
            }
            #region Defensive tracing
            else
            {
                //not different from current values.
            }
            #endregion
        }
        #endregion

        #endregion

        #region Render
        /// <summary>
        /// Paint this control.
        /// </summary>
        /// <param name="canvas">The graphics canvas to paint on.</param>
        /// <param name="context">The current renderation context.</param>
        void IVirtualControl.Render(Graphics canvas, RenderContext context)
        {
            OnRender(canvas, context);
        }
        #endregion

        #region Focus

        #region Focused
        private bool mFocused;
        /// <summary>
        /// Checks whether this control is in focus.
        /// </summary>
        public bool Focused
        {
            get { return mFocused; }
        }
        #endregion

        #region Notify Got Focus
        /// <summary>
        /// This method is invoked to inform this control that it has received focus.
        /// </summary>
        void IVirtualControl.NotifyGotFocus()
        {
            mFocused = true;
            OnGotFocus();
        }
        #endregion

        #region Notify Lost Focus
        /// <summary>
        /// This method is invoked to inform this control that it has lost focus.
        /// </summary>
        void IVirtualControl.NotifyLostFocus()
        {
            mFocused = false;
            OnLostFocus();
        }
        #endregion

        #endregion

        #region Mouse Events

        #region Notify Mouse Enter
        /// <summary>
        /// This method is invoked to inform this control that it has received Mouse Enter event.
        /// </summary>
        void IVirtualControl.NotifyMouseEnter()
        {
            OnMouseEnter();
        }
        #endregion

        #region Notify Mouse Leave
        /// <summary>
        /// This method is invoked to inform this control that it has received Mouse Leave event.
        /// </summary>
        void IVirtualControl.NotifyMouseLeave()
        {
            OnMouseLeave();
        }
        #endregion

        #region Notify Mouse Move
        /// <summary>
        /// This method is invoked to inform this control that it has received Mouse Move event.
        /// </summary>
        void IVirtualControl.NotifyMouseMove(MouseEventArgs e)
        {
            OnMouseMove(e);
        }
        #endregion

        #region Notify Mouse Up
        /// <summary>
        /// This method is invoked to inform this control that it has received Mouse Up event.
        /// </summary>
        void IVirtualControl.NotifyMouseUp(MouseEventArgs e)
        {
            OnMouseUp(e);
        }
        #endregion

        #region Notify Mouse Down
        /// <summary>
        /// This method is invoked to inform this control that it has received Mouse Down event.
        /// </summary>
        void IVirtualControl.NotifyMouseDown(MouseEventArgs e)
        {
            OnMouseDown(e);
        }
        #endregion

        #region Notify Mouse Click
        /// <summary>
        /// This method is invoked to inform this control that it has received Mouse Click event.
        /// </summary>
        void IVirtualControl.NotifyMouseClick(MouseEventArgs e)
        {
            OnMouseClick(e);
        }
        #endregion

        #region Notify Mouse Double Click
        /// <summary>
        /// This method is invoked to inform this control that it has received Mouse Double Click event.
        /// </summary>
        void IVirtualControl.NotifyMouseDoubleClick(MouseEventArgs e)
        {
            OnMouseDoubleClick(e);
        }
        #endregion

        #endregion

        #region Keyboard Events

        #region Notify Key Up
        /// <summary>
        /// This method is invoked to inform this control that it has received Key Up event.
        /// </summary>
        void IVirtualControl.NotifyKeyUp(KeyEventArgs e)
        {
            OnKeyUp(e);
        }
        #endregion

        #region Notify Key Down
        /// <summary>
        /// This method is invoked to inform this control that it has received Key Down event.
        /// </summary>
        void IVirtualControl.NotifyKeyDown(KeyPressEventArgs e)
        {
            OnKeyDown(e);
        }
        #endregion

        #region Notify Key Press
        /// <summary>
        /// This method is invoked to inform this control that it has received Key Press event.
        /// </summary>
        void IVirtualControl.NotifyKeyPress(KeyEventArgs e)
        {
            OnKeyPress(e);
        }
        #endregion

        #endregion

        #endregion
    }
}
